﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x020003D3 RID: 979
public class UpDown : Scene
{
	// Token: 0x1700025A RID: 602
	// (get) Token: 0x0600186E RID: 6254 RVA: 0x0009F8A8 File Offset: 0x0009DAA8
	// (set) Token: 0x0600186F RID: 6255 RVA: 0x0009F8B0 File Offset: 0x0009DAB0
	public string UserID { get; private set; }

	// Token: 0x06001870 RID: 6256 RVA: 0x0009F8BC File Offset: 0x0009DABC
	private void Awake()
	{
		this.netWWW = base.GetComponent<NetWWW>();
	}

	// Token: 0x06001871 RID: 6257 RVA: 0x0009F8CC File Offset: 0x0009DACC
	private void Start()
	{
		UpDown.CreateUUID();
		this.UserID = UpDown.GetUUID();
		base.InScene(true);
		this.mode = UpDown.MODE.WAIT;
	}

	// Token: 0x06001872 RID: 6258 RVA: 0x0009F8EC File Offset: 0x0009DAEC
	private void Update()
	{
		if (this.mode == UpDown.MODE.WAIT && this.inFade == null)
		{
			this.ChangeMode(UpDown.MODE.CHECK);
			this.NetWorkCheck();
		}
		if (this.mode == UpDown.MODE.CHECK && this.checkStep == UpDown.CHECK_STEP.CHECK_SERVER_COMPLETE)
		{
			this.ChangeMode(UpDown.MODE.DOWNLOAD);
		}
	}

	// Token: 0x06001873 RID: 6259 RVA: 0x0009F944 File Offset: 0x0009DB44
	public void NetWorkCheck()
	{
		GlobalData.Debug_Log("NetWorkCheck");
		this.checkStep = UpDown.CHECK_STEP.CHECK_SERVER_WAIT;
		WWWForm wwwform = new WWWForm();
		wwwform.AddField("mode", 100);
		this.netWWW.Post("http://up.illusion.jp/phome_upload/chara/master/unity/getData.php", "サーバー接続確認中...", wwwform, new NetWWW.ActWWW(this.NetWorkCheck_Complete), delegate(WWW www)
		{
			this.PostError(www, "サーバーへの接続に失敗しました");
		});
	}

	// Token: 0x06001874 RID: 6260 RVA: 0x0009F9A4 File Offset: 0x0009DBA4
	public void PostError(WWW www, string msg)
	{
		this.ShowMessage(msg);
		this.ChangeMode(UpDown.MODE.ERROR);
	}

	// Token: 0x06001875 RID: 6261 RVA: 0x0009F9B4 File Offset: 0x0009DBB4
	private void NetWorkCheck_Complete(WWW www)
	{
		if (www.text == "1")
		{
			GlobalData.Debug_Log("NetWorkCheck_Complete");
			this.checkStep = UpDown.CHECK_STEP.CHECK_SERVER_COMPLETE;
		}
		else
		{
			this.ShowMessage("アップロードサービスは終了しました");
			this.ChangeMode(UpDown.MODE.ERROR);
		}
	}

	// Token: 0x06001876 RID: 6262 RVA: 0x0009F9F4 File Offset: 0x0009DBF4
	public void ChangeMode(UpDown.MODE next)
	{
		this.mode = next;
		for (int i = 0; i < 5; i++)
		{
			this.modeRoot[i].gameObject.SetActive(i == (int)next);
		}
		if (this.mode == UpDown.MODE.CHECK)
		{
			this.modeSwapButton.gameObject.SetActive(false);
			this.checkStep = UpDown.CHECK_STEP.CHECK_WAIT;
		}
		else if (this.mode == UpDown.MODE.DOWNLOAD)
		{
			this.modeSwapButton.gameObject.SetActive(true);
			this.modeSwapButton.GetComponentInChildren<Text>().text = "アップローダー";
		}
		else if (this.mode == UpDown.MODE.UPLOAD)
		{
			this.modeSwapButton.gameObject.SetActive(true);
			this.modeSwapButton.GetComponentInChildren<Text>().text = "ダウンローダー";
		}
		else if (this.mode == UpDown.MODE.ERROR)
		{
			this.modeSwapButton.gameObject.SetActive(false);
		}
	}

	// Token: 0x06001877 RID: 6263 RVA: 0x0009FAE4 File Offset: 0x0009DCE4
	public void ShowMessage(string message)
	{
		base.GC.CreateModalMessageUI(message, null, false);
	}

	// Token: 0x06001878 RID: 6264 RVA: 0x0009FAF4 File Offset: 0x0009DCF4
	private static void CreateUUID()
	{
		string text = Application.dataPath;
		text = Path.GetDirectoryName(text);
		string path = text + "/UserData/netUID.dat";
		if (File.Exists(path))
		{
			using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					string a = binaryReader.ReadString();
					if (a != string.Empty)
					{
						return;
					}
				}
			}
		}
		string directoryName = Path.GetDirectoryName(path);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		string value = Guid.NewGuid().ToString();
		using (FileStream fileStream2 = new FileStream(path, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream2))
			{
				binaryWriter.Write(value);
			}
		}
	}

	// Token: 0x06001879 RID: 6265 RVA: 0x0009FC24 File Offset: 0x0009DE24
	private static string GetUUID()
	{
		string text = Application.dataPath;
		text = Path.GetDirectoryName(text);
		string path = text + "/UserData/netUID.dat";
		if (File.Exists(path))
		{
			using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					return binaryReader.ReadString();
				}
			}
		}
		return string.Empty;
	}

	// Token: 0x0600187A RID: 6266 RVA: 0x0009FCB4 File Offset: 0x0009DEB4
	public void OnTitleButton()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		base.GC.CreateModalYesNoUI("タイトルに戻ります\nよろしいですか？", new Action(this.ReturnTitle), null);
	}

	// Token: 0x0600187B RID: 6267 RVA: 0x0009FCDC File Offset: 0x0009DEDC
	private void ReturnTitle()
	{
		base.GC.ChangeScene("TitleScene", string.Empty, -1f);
	}

	// Token: 0x04001BE3 RID: 7139
	private const string MSG_NetWorkCheck = "サーバー接続確認中...";

	// Token: 0x04001BE4 RID: 7140
	private NetWWW netWWW;

	// Token: 0x04001BE5 RID: 7141
	private UpDown.MODE mode = UpDown.MODE.CHECK;

	// Token: 0x04001BE6 RID: 7142
	private UpDown.CHECK_STEP checkStep;

	// Token: 0x04001BE7 RID: 7143
	[SerializeField]
	private GameObject[] modeRoot = new GameObject[5];

	// Token: 0x04001BE8 RID: 7144
	[SerializeField]
	private Button modeSwapButton;

	// Token: 0x04001BEA RID: 7146
	public const int LastVersion = 0;

	// Token: 0x020003D4 RID: 980
	public enum MODE
	{
		// Token: 0x04001BEC RID: 7148
		WAIT,
		// Token: 0x04001BED RID: 7149
		CHECK,
		// Token: 0x04001BEE RID: 7150
		DOWNLOAD,
		// Token: 0x04001BEF RID: 7151
		UPLOAD,
		// Token: 0x04001BF0 RID: 7152
		ERROR,
		// Token: 0x04001BF1 RID: 7153
		NUM
	}

	// Token: 0x020003D5 RID: 981
	private enum CHECK_STEP
	{
		// Token: 0x04001BF3 RID: 7155
		CHECK_WAIT,
		// Token: 0x04001BF4 RID: 7156
		CHECK_SERVER_WAIT,
		// Token: 0x04001BF5 RID: 7157
		CHECK_SERVER_COMPLETE
	}
}
